package com.settlement.system.service.impl;

import com.settlement.system.common.annotation.Cache;
import com.settlement.system.mapper.*;
import com.settlement.system.common.exception.ServiceException;
import com.settlement.system.model.entity.common.TblRrChannel;
import com.settlement.system.service.ITblRrChannelService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.ResultHandler;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 渠道 服务实现类
 * @author xiaochuan
 * @since 2021-12-01
 */
@Slf4j
@Service
public class TblRrChannelServiceImpl extends BaseServiceImpl implements ITblRrChannelService {

    @Resource
    private TblRrChannelMapper tblRrChannelMapper;

    @Resource
    private TblRrRecordProjectMainMapper tblRrRecordProjectMainMapper;

    @Resource
    private TblReceiveRefundShopMapper tblReceiveRefundShopMapper;

    @Resource
    private TblReceiveRefundAccountMapper tblReceiveRefundAccountMapper;


    @Override
    public BaseMapper init() {
        return tblRrChannelMapper;
    }

    @Override
    public List<TblRrChannel> selectByParams(TblRrChannel tblRrChannel) throws ServiceException {
        try {
            return tblRrChannelMapper.selectByParams(tblRrChannel);
        } catch (Exception ex){
            log.error("selectByParams by tblRrChannel happen exception",ex);
            throw new ServiceException("selectByParams by tblRrChannel happen exception",ex);
        }
    }

    @Cache
    @Override
    public String getNoByName(String name) {
        try {
            return tblRrChannelMapper.getChannelNoByChannelName(name);
        } catch (Exception ex) {
            log.error("getNoByName exception", ex);
            throw new RuntimeException("getNoByName exception", ex);
        }
    }

    @Cache
    @Override
    public String getNameByNo(String no) {
        try {
            return tblRrChannelMapper.getChannelNameByChannelNo(no);
        } catch (Exception ex) {
            log.error("getNameByNo exception", ex);
            throw new RuntimeException("getNameByNo exception", ex);
        }
    }

    /**
     *
     * @param tblRrChannel
     * @return      >=4  渠道编码或渠道名称在 RR-记账项目 已使用
     *              >=2  渠道编码或渠道名称在 RR-账号设置 已使用
     *              >=1  渠道编码或渠道名称在 RR-店铺配置 已使用
     * @throws ServiceException
     */
    @Override
    public Integer selectUsedCount(TblRrChannel tblRrChannel) throws ServiceException {
        try {
            return tblRrChannelMapper.selectUsedCount(tblRrChannel);
        } catch (Exception ex){
            log.error("selectUsedCount by tblRrChannel happen exception",ex);
            throw new ServiceException("selectUsedCount by tblRrChannel happen exception",ex);
        }
    }

    @Override
    public <ModelType> Integer insert(ModelType modelType) throws ServiceException {
        Integer insert = super.insert(modelType);
        return insert;
    }

    @Override
    public <ModelType> Integer batchDelete(List<ModelType> list) throws ServiceException {
        Integer integer = super.batchDelete(list);
        return integer;
    }

    public void getEctDataByHandler(Map<String, Object> params, ResultHandler handler) {
        tblRrChannelMapper.getDataByHandler(params,handler);
    }
}

